package ks.client.controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;

import javax.swing.JFrame;

import ks.client.UserContext;
import ks.client.controllers.commands.JoinCommandController;
import ks.client.gui.GMGUI;
import ks.client.ipc.*;
import ks.client.lobby.Lobby;
import ks.client.lobby.RoomGUI;
import ks.client.kommander.*;

import org.w3c.dom.Document;

import ks.framework.common.Message;
import ks.managers.table.Table;
import ks.managers.table.TableManager;
/**
 *  This controller is a GUI based controller that gets access
 * to the Table Manager and retrieves stored table's ID.
 * Following which, constructs a command to be sent to the server.
 * 
 * @author szutshi
 */
public class JoinTableClick implements ActionListener{
	
	Lobby lobby;
	
	/**
	 * @param lobby 
	 */
	public JoinTableClick(Lobby lobby) {
		this.lobby = lobby;
		
	}
	
	public void actionPerformed(ActionEvent e){
		final int table = lobby.getTMGUI().Tables.getSelectedRow()+1;
		
		new JoinCommandController(lobby).send(table, new Action() {
			public void ack() {
				lobby.newGMGUI(table);
				
				GMGUI gui = lobby.getGMGUI();
				JFrame j = gui;
				gui.updateUserList();
				j.setVisible(true);
				gui.updateUserList();
				
			}
			
			public void nack() {
				
			}
		});
	}
}
